package org.springblogs.batch.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.listener.JobExecutionListenerSupport;
import org.springframework.stereotype.Component;

@Component
public class JobCompletionNotificationListener extends JobExecutionListenerSupport {

	private static final Logger log = LoggerFactory.getLogger(JobCompletionNotificationListener.class);

	@Override
	public void beforeJob(JobExecution jobExecution) {
		log.info(String.format("%s Start at %s", jobExecution.getJobInstance().getJobName(),
				jobExecution.getStartTime()));
	}

	@Override
	public void afterJob(JobExecution jobExecution) {
		log.info(String.format("%s finished at %s Exit Status: %s, Status: %s",
				jobExecution.getJobInstance().getJobName(), jobExecution.getEndTime(), jobExecution.getExitStatus(),
				jobExecution.getStatus()));
	}
}